home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: gail.ripco.com!mambuhl
- From: mambuhl@ripco.com (Martin Ambuhl)
- Subject: Re: HELP: What is wrong ?
- X-Nntp-Posting-Host: foley.ripco.com
- Message-ID: <DLBpyB.5D5@rci.ripco.com>
- Sender: usenet@rci.ripco.com (Net News Admin)
- Organization: Ripco Internet BBS Chicago
- Date: Wed, 17 Jan 1996 11:44:35 GMT
- X-Ident-Sender: mambuhl
-
- jinsoo@etri.re.kr (Jin-Soo Lee)
- in <4df373$kd3@ns.etri.re.kr> asks:
-
- > Your KIND HELP is needed.
- > I have some problems in the following code.
-
- >---------
-
- >#define DSKPAGESIZE 16*1024
- >#define LOGBUFSIZE 2*DSKPAGESIZE
-
- The above #defines are almost certainly wrong. Replace them with
- #define DSKPAGESIZE (16*1024)
- #define LOGBUFSIZE (2*DSKPAGESIZE)
-
- Below I have shown what your lines look like after the token replacement
- is done with your original #defines. I think you will see that they are not
- what you wanted.
-
-
- >main()
- >{
- > int pageBS, logoffset, bufferoffset, buffersize, length;
- > int freespace, inusefile;
- > char *globla_page;
- > T_LOGRECORD *tlogrec;
- >....
- >(1) pageBS = (logoffset/LOGBUFSIZE) * LOGBUFSIZE;
- pageBS = (logoffset/2*16*1024 ) * 2*16*1024 ;
-
- >....
- >(2) bufferoffset = (logoffset + length)%LOGBUFSIZE;
- bufferoffset = (logoffset + length)%2*16*1024 ;
-
- >....
- >(3) tlogrec = (T_LOGRECORD *)(global_page + (logoffset%LOGBUFSIZE));
- tlogrec = (T_LOGRECORD *)(global_page + (logoffset%2*16*1024 ));
-
- >....
- > freespace = inuselogfile - logoffset;
- >(4) if (freespace - length > sizeof(int))
- >....
- > freespace = buffersize - bufferoffset;
- >(5) if (freespace - length >= sizeof(int))
- >....
- >}
-
- >---------
-
- > The code worked well on SUN OS 4.1.3. and K&R C with dbx,
- Then either those compilers were broken or you just never noticed the problems.
-
- > but goes wrong when moved to current environment,
- > Solaris 2.4 and SUN C with SparcWorks dbx and gcc with gdb.
- > The statements (1) ~ (5) sometimes make too big or negative values.
- > I can't believe it.
- > What happened ?
- > OS or compiler problem ? or C language syntax problem ?
-
- Neither. The problem is with your code.
-
- > Any help is greatly appreciated. Please e-mail me.
- ^^^^^^^^^^^^^^^^^ Eat me.
-
- --
- * Martin Ambuhl net: mambuhl@ripco.com
- * Chicago, IL (USA)
-